package lihao.project.java;


public class CustomerList {
	private Customer[] customers;
	private int total = 0;

	
    
	public CustomerList(int totalCustomer) {
		customers = new Customer[totalCustomer];
		
	}
	public boolean addCustomer(Customer customer) {
		if(this.total >= customers.length) {
			return false;
		}
		else {
			this.customers[total++] = customer;
			return true;
		}
	}
	
	
	public boolean replaceCustomer(int index,Customer cust) {
		if(index < 0 || index >= total) {
			return false;
		}
		else {
			this.customers[index] = cust;
			return true;
		}
	}
	
	
	public boolean deleteCustomer(int index) {
		if(index < 0 || index >= total) {
			return false;
		}
		else {
			for(int i = index; i < total - 1; i++) {
				this.customers[i] = this.customers[i+1];
			}
			
			/*很细节，记得要给空出来的赋值为null*/
			customers[--total] = null;
			return true;
		}
	}
	
	public Customer[] getAllCutomers() {
		Customer[] myCustomers = new Customer[this.total];
		for(int i = 0; i < total; i++) {
			myCustomers[i] = customers[i];
		}
		return myCustomers;
	}
	
	public Customer getCustomer(int index) {
		if(index < 0 || index >= total) {
			return null;
			
		}
		else {
			return this.customers[index];
		}

	}
	
	public int getTotal() {
		return this.total;
	}
	
}
